package com.lifesting.front;

import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
//表格栏，没有render，仅供MyTable获取信息
public class Column extends UIComponentBase implements IWidthAware, ITextAware {

	public static final String COMPONENT_TYPE = "com.lifesting.column";
    public static final String COMPONENT_FAMILY = "com.lifesting.family";
    public static final Integer NON_SORT = 0;
    public static final Integer ASC_SORT=1;
    public static final Integer DES_SORT=-1;
    
	//Bean的某一field，比如person.name
	private String field;
	//排序，0没有排序，1正序，－1逆序，sortOrder改变将会触发重新分页
	private Integer sortOrder = NON_SORT;
	//是否允许排序，如果允许，将会显示排序的两个箭头
	private Boolean enableSorter = Boolean.FALSE;
	//是否允许过滤
	private Boolean enableFilter = Boolean.FALSE;
	//宽度
	private Integer width;
	//标题内容
	private String text;
	
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public Integer getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(Integer sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Boolean getEnableSorter() {
		return enableSorter;
	}

	public void setEnableSorter(Boolean enableSorter) {
		this.enableSorter = enableSorter;
	}

	public Boolean getEnableFilter() {
		return enableFilter;
	}

	public void setEnableFilter(Boolean enableFilter) {
		this.enableFilter = enableFilter;
	}

	@Override
	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;		
	}
	private Object[] values;
	@Override
	public Object saveState(FacesContext context) {
		if (values == null)
		{
			values = new Object[7];
		}
		values[0]= super.saveState(context);
		values[1] = field;
		values[2] = sortOrder;
		values[3] = enableSorter;
		values[4] = enableFilter;
		values[5] = width;
		values[6] = text;
		return values;
	}
	@Override
	public void restoreState(FacesContext context, Object state) {
		values = (Object[]) state;
		super.restoreState(context, values[0]);
		field = (String) values[1];
		sortOrder = (Integer) values[2];
		enableSorter = (Boolean) values[3];
		enableFilter = (Boolean) values[4];
		width = (Integer) values[5];
		text = (String) values[6];
	}

	public String getText() {
		return text;
	}

	public void setText(String s) {
		text = s;		
	}

}
